﻿<cfsilent>
	<cfsetting requesttimeout="900">

	<cfif StructKeyExists(form,"iterations")>
		<cfset variables.iterations = form.iterations>
	<cfelseif StructKeyExists(URL,"iterations")>
		<cfset variables.iterations = url.iterations>
	<cfelse>
		<cfset variables.iterations = 5000>
	</cfif>
</cfsilent><cfmodule template="../_header.cfm">
</cfmodule>

<form id="testForm" method="post">
	<select name="itemtypeid" id="itemTypeId">
		<option value="1">minor</option>
		<option value="2">medium</option>
		<option value="3">major</option>
	</select>
	<br/>
	<select name="ItemType" id="itemType">
		<option value="1">Armor/Shields</option>
		<option value="2">Weapons</option>
	</select>
	<br/>
	<input type="text" name="iterations" id="iterations" value="<cfoutput>#variables.iterations#</cfoutput>" size="8" />
	<br/>
	<button id="getIt">get it</button>
</form>

<table id="results">
	<thead>
		<tr>
			<th>EB</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>+1</td>
		</tr>
		<tr>
			<td>+2</td>
		</tr>
		<tr>
			<td>+3</td>
		</tr>
		<tr>
			<td>+4</td>
		</tr>
		<tr>
			<td>+5</td>
		</tr>
		<tr>
			<td>Specific</td>
		</tr>
		<tr>
			<td>Special Abilities</td>
		</tr>
		<tr>
			<td>Iterations</td>
		</tr>
	</tbody>
</table>

<table id="summary">
	<thead>
		<tr>
			<th>EB</th>
			<th>QTY</th>
			<th>%</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>+1</td>
			<td>0</td>
			<td>0</td>
		</tr>
		<tr>
			<td>+2</td>
			<td>0</td>
			<td>0</td>
		</tr>
		<tr>
			<td>+3</td>
			<td>0</td>
			<td>0</td>
		</tr>
		<tr>
			<td>+4</td>
			<td>0</td>
			<td>0</td>
		</tr>
		<tr>
			<td>+5</td>
			<td>0</td>
			<td>0</td>
		</tr>
		<tr>
			<td>Specific</td>
			<td>0</td>
			<td>0</td>
		</tr>
		<tr>
			<td>Special Abilities</td>
			<td>0</td>
			<td>0</td>
		</tr>
		<tr>
			<td>Iterations</td>
			<td>0</td>
		</tr>
	</tbody>
</table>

<cfmodule template="../_footer.cfm">
	<script type="text/javascript">
		$(document).ready( function() {
			$('#getIt').button()
			.click( function(e) {
				e.preventDefault();

				// post test form to tests.cfc::GetEnhancementBonus
				var $form = $('#testForm');
				var data = {
					method: 'GetEnhancementBonus',
					itemCategoryID: $form.find($('#itemTypeId')).val(),
					iterations: $form.find($('#iterations')).val(),
					itemTypeID: $form.find($('#itemType')).val()
				};
				var iterations = data.iterations;
				$.ajax({
					data: data,
					success: function(data) {
						var data = eval("(" + data + ")");

						$('#summary tbody tr:eq(7) td:eq(1)').html(parseInt($('#summary tbody tr:eq(7) td:eq(1)').html()) + parseInt(iterations));

						$('#results tbody tr:eq(7)').append('<td>' + parseInt(iterations) + '</td><td></td>');
						$('#results thead tr').append('<th>QTY</th><th>%</th>');
						$.each(data, function(index, value) {
							$('#results tbody tr:eq(' + index + ')').append('<td>' + parseInt(value) + '</td><td>' + Math.round(value/iterations * 100 * 100) /100 + '</td>');

							$('#summary tbody tr:eq(' + index + ') td:eq(1)').html(parseInt($('#summary tbody tr:eq(' + index + ') td:eq(1)').html()) + parseInt(value));
							$('#summary tbody tr:eq(' + index + ') td:eq(2)').html(Math.round(parseInt($('#summary tbody tr:eq(' + index + ') td:eq(1)').html()) / parseInt(parseInt($('#summary tbody tr:eq(7) td:eq(1)').html())) * 100 * 100) / 100);
						});
					}
				});
			});
		});

		$.ajaxSetup({
			data: {
				returnformat: 'json'
			},
			type: 'post',
			url: '/pathfinder/cfcs/tests.cfc'
		});
	</script>
</cfmodule>